"""
selenium 弹框处理:

    alert
    confirm
    prompt

    div弹框
    等


alert 没法直接定位 , 需要切换到 alert 中进行操作 :
    driver.switch_to.alert.text              获取弹框的文本信息
    driver.switch_to.alert.accept()          接受警告
    driver.switch_to.alert.dismiss()         忽略警告
    driver.switch_to.alert.send_keys(keys)   发送文本:keys 给弹框

driver.switch_to.alert 也可以切换到 js 代码弹框中

"""
from selenium.webdriver.common.by import By

from basic.s1_pytest_base import TestBase


class TestPopUp(TestBase):

    def test_oo1(self):
        self.driver.get('https://www.runoob.com/try/try.php?filename=tryjs_alert')
        self.driver.switch_to.frame('iframeResult')
        self.driver.find_element(By.CSS_SELECTOR, 'input[type]').click()
        alert_text = self.driver.switch_to.alert.text
        print(alert_text)
        TestBase.sleep(2)
        self.driver.switch_to.alert.accept()
        TestBase.sleep(2)
        js = 'window.alert("' + alert_text + '------------- !")'
        self.driver.execute_script(js)
        TestBase.sleep(2)
        self.driver.switch_to.alert.accept()
